package dao.impl;


import advanced.StudentRowMapper;
import dao.StudentDao;
import entity.Student;
import com.qf.utils.DaoUtils;

import java.util.List;

/*
杨威
2021/9/6
15:34
*/
public class StudentDaoImpl implements StudentDao {
    public int insert(Student student) {
        String sql="insert into student (stu_name,stu_gender,stu_phone,bornDate,stu_email,stu_address,grade_id)values(?,?,?,?,?,?,?);";
        return DaoUtils.commonsUpdate(sql,student.getStuName(),student.getStuGender(),student.getStuPhone(),student.getBornDate(),student.getStuEmail(),student.getStuAddress(),student.getGradeId());
    }

    public int update(Student student) {
        String sql="update student set stu_name=?,stu_gender=?,stu_phone=?,bornDate=?,stu_email=?,stu_address=?,grade_id=? where stu_id=?";
        return DaoUtils.commonsUpdate(sql,student.getStuName(),student.getStuGender(),student.getStuPhone(),student.getBornDate(),student.getStuEmail(),student.getStuAddress(),student.getGradeId(),student.getStuId());
    }

    public int delete(int id) {
        String sql="delete from student where stu_id=?";
        return DaoUtils.commonsUpdate(sql,id);
    }

    public List<Student> selectOne(int stu_id) {
        String sql="select * from student where stu_id=?";
        return DaoUtils.commonsSelect(sql, new StudentRowMapper(), stu_id);
    }

    public List<Student> selectAll() {
       String sql="select * from student;";
       return DaoUtils.commonsSelect(sql,new StudentRowMapper(),null);
    }
}
